<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    Netty websocket time server:
</head>
</br>
<body>
</br>
<script type="text/javascript">
    var socket;
    if (!window.WebSocket) {
//        window.WebSocket = window
        alert("not WebSocket");
    }
    if (window.WebSocket) {
        socket = new WebSocket("ws://127.0.0.1:51234/websocket");
        socket.onmessage = function (event) {
            var resposeTextObj = document.getElementById("resposeText");
            resposeTextObj.value = event.data;
        };

        socket.onopen = function (event) {
            var resposeTextObj = document.getElementById("resposeText");
            resposeTextObj.value = "打开服务器正常，浏览器支持Websocket。";
        };

        socket.onclose = function (event) {
            var resposeTextObj = document.getElementById("resposeText");
            resposeTextObj.value = "Websocket关闭。";
        }
    } else {
        alert("当前浏览器不支持websocket!!!")
    }

    function sendMsg(msg) {
        if (!window.WebSocket) {
            return
        }
        if (socket.readyState == WebSocket.OPEN) {
            socket.send(msg);
        } else {
            alert("Websocket 还没有建立连接！！！")
        }
    }
</script>

<form onsubmit="return false;">
    <input type="text" style="width: 500px; height: 100px"  name="msg" value="Websocket time server by netty."/>
    </br>
    </br>
    </br>
    <input type="button" value="发送消息到服务器" onclick="sendMsg(this.form.msg.value)"/>
    </br>
    </br>
    <hr color="blue"/>
    <h3>服务器返回应答消息：</h3>
    <textarea id="resposeText" style="width: 800px; height: 300px" ></textarea>

</form>
</body>
</html>